package experimentUI;
import javax.swing.*;
import java.awt.*;
/*
    第一个实验，自组电位差计的UI及交互逻辑设计
 */
public class Circuit1UI {

    public absolutePositionFrame mainFrame= new absolutePositionFrame("电位差计实验模拟");

    public JLabel imageS1,imageS2;
    public JLabel outUOfPower,outIOfPower,outIOfG;
    public JTextField inputPower = new JTextField();
    public JButton powerInputConfirm = new JButton("确认");

    public whiteButton buttonPower = new whiteButton();
    public whiteButton buttonEx = new whiteButton();
    public whiteButton buttonEn =  new whiteButton();
    public whiteButton buttonR1 = new whiteButton();
    public whiteButton buttonR2 = new whiteButton();
    public whiteButton buttonS1 = new whiteButton();
    public whiteButton buttonS2 = new whiteButton();
    public whiteButton buttonG = new whiteButton("G");

    /*
        构造函数也是该模块主函数
     */
    public Circuit1UI(){
        mainFrame.BackgroundImage("Circuit1.png");
        System.out.println("Created Successful");
        setButtons();
        Container container = mainFrame.getContentPane();
        addButtons(container);
        mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    /*
        设定按钮位置
     */
    private void setButtons(){
        buttonPower.setBounds(400,100,200,80);
        buttonEn.setBounds(400,600,150,60);
        buttonEx.setBounds(400,415,150,60);
        buttonG.setBounds(650,370,120,120);
        buttonG.setFont(new Font("宋体",Font.BOLD,32));
        buttonR1.setBounds(380,275,140,80);
        buttonR2.setBounds(750,275,140,80);
        inputPower.setBounds(400,180,100,25);
        inputPower.setVisible(false);
        powerInputConfirm.setBounds(510,180,80,25);
        powerInputConfirm.setVisible(false);


        outUOfPower=new JLabel();
        outUOfPower.setBounds(350,30,150,20);
        outUOfPower.setVisible(true);
        outIOfPower=new JLabel();
        outIOfPower.setBounds(350,50,150,20);
        outIOfPower.setVisible(true);
        outIOfG = new JLabel();
        outIOfG.setBounds(770,430,150,20);
        outIOfG.setVisible(true);
    }

    /*
        把按钮添加到容器里
     */
    private void addButtons(Container container){
        container.add(buttonPower);
        container.add(buttonEx);
        container.add(buttonEn);
        container.add(buttonG);
        container.add(buttonR1);
        container.add(buttonR2);
        imageS1=buttonS1.addBackgroundImage(container,"S1ON.png",680,110,50,50);
        imageS1.setVisible(false);
        imageS2=buttonS2.addBackgroundImage(container,"S2null.png",560,495,78,89);

        container.add(inputPower);
        container.add(powerInputConfirm);
        container.add(outUOfPower);
        container.add(outIOfPower);
        container.add(outIOfG);
    }



}
